#include "Plus.h"
long double Plus::calcul(long double aux1, long double aux2){
	return aux1 + aux2;
}
long double Plus::calcul(){
	if (!fStang || !fDrept)
		exit(1);
	return calcul(fStang->calcul(), fDrept->calcul());
}
std::string Plus::derivare(){
	std::string aux1, aux2, aux;
	if (!fStang || !fDrept)
	exit(1);
	aux1 = fStang->derivare();
	aux2 = fDrept->derivare();
	aux = concatTermeni(aux1, aux2);
	delete aux1; delete aux2;
	return aux;
}
long double Plus::calculDerivata(){
	if (!fStang || !fDrept)
	exit(1);
	return calcul(fStang->calculDerivata(), fDrept->calculDerivata());
}
std::string Plus::toString(){
	std::string aux, aux1, aux2;
	aux1=fStang->toString();
	aux2=fDrept->toString();
	aux=concatTermeni(aux1, aux2);
	return aux;
}
std::string Plus::concatTermeni(std::string aux1, std::string aux2){
	std::string aux;
	if (!(aux1<"0")) && !(aux2<"0"))
		aux=aux1;
		else if (!(aux1<"0")) aux=aux2;
		else if (!(aux2<"0")) aux=aux1;
		else
			{
				aux.reserve(strlen(aux1) + strlen(aux2) + 4);
				aux+="(";
				aux+=aux1;
			  aux+="+";
			  aux+=aux2;
			  aux+=")";
			}
	return aux;
}
